import java.util.Stack;

public class Leet16_26 {
    public static void main(String[] args) {
        System.out.println(calculate("3+5 / 2"));
    }
    static public int calculate(String s) {
        StringBuilder sb = new StringBuilder();
        Stack<Integer> stack = new Stack<>();
        s = s.replace(" ","");
        s+="=";
        int mod = -1;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i)<='9'&&s.charAt(i)>='0'){
                sb.append(s.charAt(i));
            }else if (mod == 1||mod == -1){
                stack.push(Integer.parseInt(sb.toString()));
                sb = new StringBuilder();
            }else if(mod == 2){
                stack.push(-Integer.parseInt(sb.toString()));
                sb = new StringBuilder();
            }else if(mod == 3){
                int num = stack.pop();
                stack.push(num*Integer.parseInt(sb.toString()));
                sb = new StringBuilder();
            }else {
                int num = stack.pop();
                stack.push(num/Integer.parseInt(sb.toString()));
                sb = new StringBuilder();
            }

            if(s.charAt(i)=='+'){
                  mod = 1;
            }else if(s.charAt(i)=='-'){
                  mod = 2;
            }else if(s.charAt(i)=='*'){
                  mod = 3;
            }else if(s.charAt(i)=='/'){
                  mod = 4;
            }
        }
        int re = 0;
        for (Integer integer : stack) {
            re+=integer;
        }
        return re;
    }
}
